/*
 * Created on Oct 4, 2003
 *
 * Mihai Postelnicu
 * 
 */
package ro.gateway.aida.stats;

import java.util.Enumeration;
import java.util.Vector;

/**
 * @author Mihai Postelnicu
 * StatsHolder
 *  
 * */
public class StatsHolder extends Vector {
	
	public StatsHolder(String name) {
		super();
		this.name=name;
	}
	protected String name;
	
	public long getCount() {
		long count=0;
		Enumeration en=elements();
			while (en.hasMoreElements()) {
				StatsItem element = (StatsItem) en.nextElement();
				count+=element.getCount();
			}
			return count;
		}
	
	public boolean incById(long id,long amount) {
		StatsItem si=findById(id);
		if (si==null) return false;
		si.inc(amount);
		return true;
 	}
	
	public StatsItem findById(long id) {
		Enumeration en=elements();
		while (en.hasMoreElements()) {
			StatsItem element = (StatsItem) en.nextElement();
			if (element.getId()==id) return element;
		}
		return null;
	}

}
